﻿using Extensions;
using System;
using System.Data;
using System.Windows.Forms;

namespace ConfOrder.Shirt
{
    public partial class OrderRef : XPopupForm
    {
        public OrderRef(int OrderRefId)
        {
            InitializeComponent();
            this.OrderRefId = OrderRefId;
        }

        public int OrderRefId;
        private void OrderRef_Load(object sender, EventArgs e)
        {
            gridView1.Init("COGetAyrim");
            gridView1.MakeReadOnly();
            gridView1.MakeRowSelectable();
            gridView1.FormatAsNumber(0, "TotalShirts", "EstimatedQty");
            gridView1.FormatAsPercentage("CompletionPct");
            gridView1.BestFitColumns();

            if(OrderRefId>0)
            {
                gridView1.FocusedRowHandle = gridView1.LocateByValue("OrderRefId", OrderRefId);
                gridView1.MakeRowVisible(gridView1.FocusedRowHandle);
            }
        }

        private void gridView1_DoubleClick(object sender, EventArgs e)
        {
            DataRow dr = gridView1.GetFocusedDataRow();
            OrderRefId = dr["OrderRefId"].ToIntZero();

            if (OrderRefId > 0)
                this.DialogResult = DialogResult.OK;
        }
    }
}
